import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * LongWritable, Text ===> Map输入    <偏移量，手机号>
 * Text, FlowBean  ======> Map的输出：<手机号、流量上传下载总和>
 */

public class FlowCountMapper  extends Mapper<LongWritable, Text,Text,FlowBean> {
    Text k = new Text();
    FlowBean v = new FlowBean();

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        // per line

        String[] fields = value.toString().split("\t");
        int len = fields.length;
//        System.out.println( len );
        String phoneNumber = fields[1];
        String upFlow = fields[len - 3];
        String downFlow = fields[len - 2];

        k.set(phoneNumber);

        context.write(k,new FlowBean(Long.parseLong(upFlow), Long.parseLong(downFlow)));
    }
}
